﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Lincolnwood.Foundation.Common.Data;
using Lincolnwood.Foundation.Common.Data.NHibernate;
using NHibernate;
using NHibernate.Linq;

namespace Lincolnwood.Foundation.SermonLibrary.Data.NHibernate
{
    public class NHibernateSermonSeriesRepository : NHibernateRepositoryBase<SermonSeries, Guid>, ISermonSeriesRepository
    {
        public NHibernateSermonSeriesRepository(IUnitOfWork unitOfWork)
            : base((NHibernateUnitOfWork)unitOfWork)
        { }


        public IList<SermonSeries> GetSermonsSeriesPaged(int pageIndex, int itemsPerPage)
        {
            int startRow = pageIndex > 0 ? (pageIndex - 1) * itemsPerPage : 0;

            var query = UnitOfWork.Session.CreateQuery("FROM SermonSeries s");
            query.SetFirstResult(startRow);
            query.SetMaxResults(itemsPerPage);

            IList<SermonSeries> sermons = query.List<SermonSeries>();
            return sermons;
        }

        public override void Merge(SermonSeries entity)
        {
            throw new NotImplementedException();
        }
    }
}
